<template>
	<div class="auditManager w944">
		<alert ref="alert"></alert>
		<deleteAlert ref="deleteAlert"></deleteAlert>
		<div class="label_top">
			<p><i class="line"></i>审核小组</p>
		</div>
		<div class="label_bot">
			<div class="el-tabs-report">
				<a class="listOne" @click="createGrope">创建小组</a>
				<div class="msearch">
					<input placeholder="请输入小组名称……" v-model="search"/>
					<a @click="getTableList"><img src="../../assets/qudaoImg/search.png"/></a>
				</div>
			</div>
			<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
				<el-table-column label="序号" width="120">
					<template slot-scope="scope">{{ scope.row.sort}}</template>
				</el-table-column>
				<el-table-column prop="name" label="小组名称"></el-table-column>
				<el-table-column prop="nickname" label="小组详情">
					<template slot-scope="scope">
						<el-button @click="handleSeen(scope.row)">查看</el-button>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="160">
					<template slot-scope="scope">
						<el-button @click="handleEdit(scope.row)">编辑</el-button>
						<el-button @click="handleDelete(scope.row)" class="red">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="fenyeMargin">
				<div class="pag_block">
					<el-pagination @current-change="handleCurrentChange" :current-page="currentpage" :page-size="pagesize" layout="prev, pager, next" :total="total"></el-pagination>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import alert from '../../components/Alert.vue';
	import deleteAlert from '../../components/deleteAlert.vue';
	export default {
		data() {
			return {
				sort:'',
				search:'',
				tableData: [],
				pagesize: 15,
				currentpage: 1,
				total: 1,
				deleteType:'delete',
				multipleSelection: []
			}
		},
		methods:{
			getParams() {
				this.rootcompanyid = this.$route.params.rootcompanyid;
				this.getTableList();
			},
			getTableList(){
				this.$ajax({
					url: this.$root.jifuUrl + "/getAuditTeamPage?"+'page='+this.currentpage+'&num='+this.pagesize+'&rootcompanyid=1',
					method: 'GET',
					data: {},
					success: res => {
						if(res.data.code == 200) {
							this.tableData = res.data.data.list;
							this.total=res.data.data.pageParam.items;
							for(var i = 0;i<this.tableData.length;i++){
								this.tableData[i].sort=i+1
							}
						}
					}
				});
			},
			handleEdit(row) {
				this.$ajax({
					url: this.$root.jifuUrl + "/getAuditTeamById?id="+row.id,
					method: 'GET',
					data: {},
					success: res => {
						if(res.data.code == 200) {
							this.$router.push({
								name: 'createAuditGrope',
								params: {
									type: 'edit'
								}
							})
							this.$root.auditMsg = res.data.data;
						}
					}
				});
			},
			handleSeen(row) {
				this.$ajax({
					url: this.$root.jifuUrl + "/getAuditTeamById?id="+row.id,
					method: 'GET',
					data: {},
					success: res => {
						if(res.data.code == 200) {
							this.$router.push({
								name: 'createAuditGrope',
								params: {
									type: 'see'
								}
							})
							this.$root.auditMsg = res.data.data;
						}
					}
				});
			},
			handleDelete(row){
				this.transitionRow = row;
				this.$rootFunction().rootDelete();
			},
			handleDeleteAll() {
				this.$rootFunction().rootDeleteAll();
			},
			deleteSubmit() {
				if(this.deleteType == 'delete'){
					let s={ids:this.transitionRow.id}
					this.$ajax({ 
						url: this.$root.jifuUrl + "/deleteAuditTeam",
						method: 'POST',
						data:this.qs.stringify(s),
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}else{
					let s={ids:this.multipleSelection.join(',')};
					this.$ajax({ 
						url: this.$root.jifuUrl + "/deleteAuditTeam",
						data:this.qs.stringify(s),
						method: 'POST',
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}
			},
			createGrope(){
				this.$router.push({
					name:'createAuditGrope'
				})
			},
			handleCurrentChange(value) {
				this.currentpage = value;
				this.getTableList();
			},
			toggleSelection(rows) {
				if(rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row, !this.allSelect)
					})
					this.allSelect = !this.allSelect;
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = [];
				for(var i = 0;i<val.length;i++){
					var s={id:val[i].id}
					this.multipleSelection.push(s)
				}
			}
		},
		components: {
			alert,
			deleteAlert
		},
		mounted(){
			this.getParams();
			this.getTableList();
		}
	}
</script>